import store from '@/store';
import { useMemo } from 'react';

/**
 * 获取用户基本信息的hook，主要是针对userName做了一些逻辑判断
 * @returns
 */
export default function useUserInfo() {
  const [userState] = store.useModel('user');

  const userName = useMemo(() => {
    if (!userState.baseInfo) return '';
    const { employeeNo, name, realEnName, realNameVisibility } = userState.baseInfo;
    if (realNameVisibility === 1) return name || realEnName || employeeNo;
    return realEnName || name || employeeNo;
  }, [userState.baseInfo]);

  return { ...userState.baseInfo, userName };
}
